package org.aldar.bquest.util;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.aldar.bquest.screens.StartMenuScreen;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * User: Daria
 * Date: 12/6/14 3:41 PM
 */
public class ExceptionUtil {


    public static void logThrowable(Throwable t, Context context, SQLiteHelper sqLiteHelper) {
        Log.e("aldar", "Exception caught: ", t);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        sqLiteHelper.logException(sw.toString());
        GMailSender sender = new GMailSender("loonyrocket.service@gmail.com", "iamdasha84");
        try {
            sender.sendMail("Exception caught: '" + t.getMessage() + "'",
                    sw.toString(),
                    "daria.aparina@gmail.com",
                    "daria.aparina@gmail.com");
        } catch (Exception e) {
            Log.e("SendMail", e.getMessage(), e);
        }

        Intent intent = new Intent();
        intent.setClass(context.getApplicationContext(), StartMenuScreen.class);
        //intent.putExtra("showReport", "true");
        StartMenuScreen.showErrorReport = true;
        context.startActivity(intent);
        //MainBoardScreen.screenInstance.finish();


        //throw new RuntimeException("Rethrown my throwable", t);

    }

}
